
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>001-两数之和 · Dragon GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Bruse-Lee">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Ice.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://tinytalking.blackdragonlee.com/login" target="_blank" class="custom-link">MyTinyTalk</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">简介</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">My Life👓</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../Family.html">
            
                <a href="../Family.html">
            
                    
                    👦🏼全家福
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../ListBook.html">
            
                <a href="../ListBook.html">
            
                    
                    百科全书📕
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../Basketball.html">
            
                <a href="../Basketball.html">
            
                    
                    篮球🤾🏾‍♂️所带给我的一切
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../secret.html">
            
                <a href="../secret.html">
            
                    
                    与老友🧙🏼‍♂️彻夜长谈的秘密
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">My Technical Summary🧰</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../book.html">
            
                <a href="../book.html">
            
                    
                    Gitbook的那些事🌟
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../FileOnline.html">
            
                <a href="../FileOnline.html">
            
                    
                    💥项目上线的那些事
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../lock.html">
            
                <a href="../lock.html">
            
                    
                    🤔悲观锁和😀乐观锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ShareHand.html">
            
                <a href="../ShareHand.html">
            
                    
                    三次握手🤝,四次挥手👋得这么讲
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../RemoveRestrictions.html">
            
                <a href="../RemoveRestrictions.html">
            
                    
                    解除网盘下载速度限制🚀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../Bilibili.html">
            
                <a href="../Bilibili.html">
            
                    
                    📺小破站的爱恨情仇
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">My Technical Document⏳</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../CSharp/">
            
                <a href="../CSharp/">
            
                    
                    C#设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../CSharp/Singleton.html">
            
                <a href="../CSharp/Singleton.html">
            
                    
                    第一节-单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../CSharp/Factory.html">
            
                <a href="../CSharp/Factory.html">
            
                    
                    第二节-简单工程和工厂方法模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis缓存三大问题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="../Redis/penetrate.html">
            
                <a href="../Redis/penetrate.html">
            
                    
                    001-缓存穿透
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="../Redis/breakdown.html">
            
                <a href="../Redis/breakdown.html">
            
                    
                    002-缓存击穿
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.3" data-path="../Redis/avalanche.html">
            
                <a href="../Redis/avalanche.html">
            
                    
                    003-缓存雪崩
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">My Practice Topic</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="./">
            
                <a href="./">
            
                    
                    LeetCode刷题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="5.1.1" data-path="Sum.html">
            
                <a href="Sum.html">
            
                    
                    001-两数之和
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="Ice.html">
            
                <a href="Ice.html">
            
                    
                    002-雪糕的最大数量
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >001-两数之和</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="001-&#x4E24;&#x6570;&#x4E4B;&#x548C;">001-&#x4E24;&#x6570;&#x4E4B;&#x548C;</h1>
<p><strong>&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x6570;&#x7EC4; nums &#x548C;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x76EE;&#x6807;&#x503C; target&#xFF0C;&#x8BF7;&#x4F60;&#x5728;&#x8BE5;&#x6570;&#x7EC4;&#x4E2D;&#x627E;&#x51FA; &#x548C;&#x4E3A;&#x76EE;&#x6807;&#x503C; target  &#x7684;&#x90A3; &#x4E24;&#x4E2A; &#x6574;&#x6570;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x5B83;&#x4EEC;&#x7684;&#x6570;&#x7EC4;&#x4E0B;&#x6807;&#x3002;</strong></p>
<p><strong>&#x4F60;&#x53EF;&#x4EE5;&#x5047;&#x8BBE;&#x6BCF;&#x79CD;&#x8F93;&#x5165;&#x53EA;&#x4F1A;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x7B54;&#x6848;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x6570;&#x7EC4;&#x4E2D;&#x540C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5728;&#x7B54;&#x6848;&#x91CC;&#x4E0D;&#x80FD;&#x91CD;&#x590D;&#x51FA;&#x73B0;&#x3002;</strong></p>
<p><strong>&#x4F60;&#x53EF;&#x4EE5;&#x6309;&#x4EFB;&#x610F;&#x987A;&#x5E8F;&#x8FD4;&#x56DE;&#x7B54;&#x6848;&#x3002;</strong></p>
<p><strong>&#x793A;&#x4F8B; 1&#xFF1A;</strong></p>
<pre><code>&#x8F93;&#x5165;&#xFF1A;nums = [2,7,11,15], target = 9
&#x8F93;&#x51FA;&#xFF1A;[0,1]
&#x89E3;&#x91CA;&#xFF1A;&#x56E0;&#x4E3A; nums[0] + nums[1] == 9 &#xFF0C;&#x8FD4;&#x56DE; [0, 1] &#x3002;
</code></pre><p><strong>&#x63D0;&#x793A;&#xFF1A;</strong></p>
<pre><code>2 &lt;= nums.length &lt;= 104
-109 &lt;= nums[i] &lt;= 109
-109 &lt;= target &lt;= 109
&#x53EA;&#x4F1A;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x6709;&#x6548;&#x7B54;&#x6848;
</code></pre><h2 id="&#x9898;&#x89E3;">&#x9898;&#x89E3;</h2>
<h3 id="&#x65B9;&#x6CD5;&#xFF1A;&#x66B4;&#x529B;&#x679A;&#x4E3E;">&#x65B9;&#x6CD5;&#xFF1A;&#x66B4;&#x529B;&#x679A;&#x4E3E;</h3>
<p><strong>&#x601D;&#x8DEF;&#x53CA;&#x7B97;&#x6CD5;</strong></p>
<blockquote>
<p>&#x6700;&#x5BB9;&#x6613;&#x60F3;&#x5230;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x679A;&#x4E3E;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x6570; x&#xFF0C;&#x5BFB;&#x627E;&#x6570;&#x7EC4;&#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728; target - x&#x3002;
&#x5F53;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x904D;&#x5386;&#x6574;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x5F0F;&#x5BFB;&#x627E; target - x &#x65F6;&#xFF0C;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x5230;&#x6BCF;&#x4E00;&#x4E2A;&#x4F4D;&#x4E8E; x &#x4E4B;&#x524D;&#x7684;&#x5143;&#x7D20;&#x90FD;&#x5DF2;&#x7ECF;&#x548C; x &#x5339;&#x914D;&#x8FC7;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x9700;&#x8981;&#x518D;&#x8FDB;&#x884C;&#x5339;&#x914D;&#x3002;&#x800C;&#x6BCF;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E0D;&#x80FD;&#x88AB;&#x4F7F;&#x7528;&#x4E24;&#x6B21;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x5728; x &#x540E;&#x9762;&#x7684;&#x5143;&#x7D20;&#x4E2D;&#x5BFB;&#x627E; target - x&#x3002;</p>
</blockquote>
<pre><code>public class Solution {
    public int[] TwoSum(int[] nums, int target) {
        int n = nums.length;
        for(int i = 0;i&lt;=n;++i){
            for(int j = i+1;j&lt;=n;++j){
                if(nums[i]+nums[j] == target){
                    return new int[]{i,j};
                };
            };
        return new int[0];
        };
    }
}
</code></pre><footer class="page-footer"><span class="copyright">Copyright &#xA9; book.blackdragonlee.com 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x5185;&#x5BB9;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2021-07-02 12:38:24
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: LeetCode刷题">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Ice.html" class="navigation navigation-next " aria-label="Next page: 002-雪糕的最大数量">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"001-两数之和","level":"5.1.1","depth":2,"next":{"title":"002-雪糕的最大数量","level":"5.1.2","depth":2,"path":"LeetCode/Ice.md","ref":"LeetCode/Ice.md","articles":[]},"previous":{"title":"LeetCode刷题","level":"5.1","depth":1,"path":"LeetCode/README.md","ref":"LeetCode/README.md","articles":[{"title":"001-两数之和","level":"5.1.1","depth":2,"path":"LeetCode/Sum.md","ref":"LeetCode/Sum.md","articles":[]},{"title":"002-雪糕的最大数量","level":"5.1.2","depth":2,"path":"LeetCode/Ice.md","ref":"LeetCode/Ice.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","back-to-top-button","-lunr","-search","search-pro","splitter","tbfed-pagefooter","github","pageview-count","page-toc-button","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy book.blackdragonlee.com 2021","modify_label":"该内容更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"pluginsConfig":{"page-toc-button":{"maxTocDepth":2,"minTocSize":2}},"github":{"url":"https://github.com/Bruse-Lee"},"livereload":{},"splitter":{},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"page-toc-button":{},"back-to-top-button":{},"pageview-count":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Bruse-Lee","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Dragon GitBook","language":"zh-hans","links":{"sidebar":{"MyTinyTalk":"http://tinytalking.blackdragonlee.com/login"}},"gitbook":"*","description":"记录日常学习的技术文档与生活趣事"},"file":{"path":"LeetCode/Sum.md","mtime":"2021-07-02T04:38:24.747Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-07-02T13:59:02.253Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

